/*
 * 文  件   名： FoodAndDrinkNowActivity.java
 * 版          权： Copyright GoPawPaw All Rights Reserved.
 * 描          述：[该类的简要描述]
 * 创  建   人： LiJinHua
 * 创建时间： 2012-5-29
 * 
 * 修   改  人：
 * 修改时间：
 * 修改内容：[修改内容]
 */
/*
 * 文  件   名： FoodAndDrinkNowActivity.java
 * 版          权： Copyright GoPawPaw All Rights Reserved.
 * 描          述：[该类的简要描述]
 * 创  建   人： LiJinHua
 * 创建时间： 2012-5-29
 * 
 * 修   改  人：
 * 修改时间：
 * 修改内容：[修改内容]
 */
package com.longevityassistant.activity.home;

import java.util.Calendar;
import java.util.Date;
import java.util.Map;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import app.adapter.TableAdapter;
import app.utils.CommonUtils;
import app.utils.Tools;
import app.widget.MenuDialog;
import app.widget.PullScrollView;
import app.widget.TableView;
import app.widget.calendar.dialog.OnDialogScrollEndListener;
import app.widget.calendar.dialog.TimeDialog;
import app.widget.calendar.dialog.TimeDialog.OnYearMonthDayTimeDialogScrollEndListener;
import app.widget.calendar.dialog.YearMonthDayDialog;

import com.longevityassistant.activity.BaseTabActivity;
import com.longevityassistant.activity.R;


/**
 * [功能简要说明]<BR>
 * [功能详细描述]
 * @author LiJinHua
 * @version [Android 1.0.0, 2012-5-29] 
 */
public class FoodAndDrinkNowActivity extends BaseTabActivity implements
OnClickListener{

	/**
	 * Log标签
	 */
	private static final String TAG = FoodAndDrinkNowActivity.class
			.getSimpleName();

	/**
	 * 用于startActivityForResult
	 */
	private static final int REQUEST_ACTIVITY_CODE = 12;
	
	/**
	 * 关掉老虎动画
	 */
	private static final int MSG_DISMISS_TIGER = 1009;

	/**
	 * 显示老虎动画
	 */
	private static final int MSG_SHOW_TIGER = 1010;

	/**
	 * 贷款列表
	 */
	private TableView mTableViewLoanList;

	/**
	 * 贷款信息列表
	 */
	private TableAdapter mTableAdapterLoan;

	/**
	 * 表头列名
	 */
	private String[] mTableHeader = null;



	/**
	 * 底部布局
	 */
	private int[] mFooterTo = new int[] { R.id.textView1 };

	/**
	 * 底部数据
	 */
	private String[] footerData = null;

	/**
	 * 菜单对话框
	 */
	private MenuDialog mMenuDialog;

	/**
	 * 菜单项
	 */
	private String[] menuItems = null;


	/**
	 * 当前贷款数据
	 */
	private Map<String, Object> mCurrentLoanSelected;

	/**
	 * PullScrollView
	 */
	private PullScrollView mPullScrollView;

	private Context mContext;

	private TextView  mTextViewDate;
	
	private TextView  mTextViewTime;
	
	private Button mBtnAdd;

	/**
	 * 时间格式化
	 */
	public static final String DATA_FORMAT = "yyyy-MM-dd";
	
	@Override
	public void init() {
		// TODO Auto-generated method stub
		super.init();

		if (getParent() != null) {
			mContext = getParent();
		} else {
			mContext = this;
		}
		
		setContentView(R.layout.layout_food_and_drink_now);

//		mTableViewLoanList = (TableView) findViewById(R.id.tableview_list);
		mPullScrollView = (PullScrollView) findViewById(R.id.scroll_view);
		mTextViewDate = (TextView) findViewById(R.id.textview_date);
		mTextViewTime = (TextView) findViewById(R.id.textview_time);
		mBtnAdd = (Button) findViewById(R.id.button_add);
		
		mTextViewDate.setOnClickListener(this);
		mTextViewTime.setOnClickListener(this);
		mBtnAdd.setOnClickListener(this);
		
		
		Date curDate = CommonUtils.getCurrentTimeByCalendar().getTime();
		
		mTextViewDate.setText(Tools.getStrDataDistanceByMonth(0,
				DATA_FORMAT, curDate));
	}

	
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.textview_date:
			// 选择开始日期
			showDateDialog();
			break;
		case R.id.textview_time:
			// 选择开始日期
			showTimeDialog();
			break;
		case R.id.button_add:
			// 执行添加
			Intent intent = new Intent(this,FoodAndDrinkSelectActivity.class);
			startActivityForResult(intent, 80);
			break;
		default:
			break;
		}
	}

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述]
	 */
	private void showDateDialog() {
		
		Calendar minTime = Calendar.getInstance();
		minTime.set(Calendar.YEAR, 1900);
		Calendar maxTime = Calendar.getInstance();

		YearMonthDayDialog mYearMonthDayDialog = new YearMonthDayDialog(this,
				"选择日期", minTime, maxTime);
		mYearMonthDayDialog.setOnDialogScrollEndListener(new OnDialogScrollEndListener(){

			@Override
			public void onDialogScrollEnd(String result) {
				// TODO Auto-generated method stub
				mTextViewDate.setText(result);
			}
		});
		mYearMonthDayDialog.setScrollBrith(true);
		

		mYearMonthDayDialog.show();
	}

	private void showTimeDialog() {
		
		final TimeDialog dialog = new TimeDialog(this,
				"选择时间");
		dialog.setOnYearMonthDayTimeDialogScrollEndListener(new OnYearMonthDayTimeDialogScrollEndListener() {

			@Override
			public void onYearMonthDayTimeDialogScrollEndListener(String hour,
					String minu) {
				mTextViewTime.setText(hour+":"+minu);
			}
		});
		
		dialog.show();
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
	}
}

